﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class DelayInvoke : MonoBehaviour
{
    public float time;
    public bool stop;
    public UnityEvent invoke;
    
    float _time = 0;
    bool isStop;

    private void Awake()
    {
        isStop = stop;
    }

    public void StartTime()
    {
        stop = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (_time == -1 || stop)
        {
            return;
        }
        _time += Time.deltaTime;
        if (_time >= time)
        {
            invoke?.Invoke();
            _time = -1;
        }
    }
    private void OnEnable()
    {
        _time = 0;
        stop = isStop;
    }
}
